//?引入路由组件
import AddCartSuccess from "@/pages/AddCartSuccess";
import Center from "@/pages/Center";
import Detail from "@/pages/Detail";
import Login from "@/pages/Login";
import Pay from "@/pages/Pay";
import PaySuccess from "@/pages/PaySuccess";
import Register from "@/pages/Register";
import Search from "@/pages/Search";
import ShopCart from "@/pages/ShopCart";
import Trade from "@/pages/Trade";
import MyOrder from "@/pages/Center/myOrder";
import GroupOrder from "@/pages/Center/groupOrder";

//?引入二级路由组件

//?路由配置信息
export default [
  {
    path: "/home",
    component: () => import("@/pages/Home"),
    //#路由元信息控制页脚
    meta: { show: true },
  },
  {
    path: "/search/:keyword?",
    component: () => import("@/pages/Search"),
    meta: { show: true },
    name: "search",
  },
  {
    path: "/login",
    component: () => import("@/pages/Login"),
    meta: { show: false },
  },
  {
    path: "/register",
    component: () => import("@/pages/Register"),
    meta: { show: false },
  },
  {
    path: "/detail/:skuid",
    component: () => import("@/pages/Detail"),
    meta: { show: true },
  },
  {
    path: "/addcartsuccess",
    name: "addcartsuccess",
    component: () => import("@/pages/AddCartSuccess"),
    meta: { show: true },
  },
  {
    path: "/shopcart",
    component: () => import("@/pages/ShopCart"),
    meta: { show: true },
  },
  {
    path: "/trade",
    component: () => import("@/pages/Trade"),
    meta: { show: true },
    //>路由独享守卫
    beforeEnter: (to, from, next) => {
      if (from.path == "/shopcart") {
        next();
      } else {
        //其他的路由而来停留在当前
        next(false);
      }
    },
  },
  {
    path: "/pay",
    component: Pay,
    meta: { show: true },
    beforeEnter: (to, from, next) => {
      if (from.path == "/trade") {
        next();
      } else {
        next(false);
      }
    },
  },
  {
    path: "/paysuccess",
    component: PaySuccess,
    meta: { show: true },
  },
  {
    path: "/center",
    component: Center,
    meta: { show: true },
    // .二级路由组件
    children: [
      {
        path: "myorder",
        component: MyOrder,
      },
      {
        path: "grouporder",
        component: GroupOrder,
      },
      {
        path: "/center",
        redirect: "/center/myorder",
      },
    ],
  },
  //重定向
  {
    path: "*",
    redirect: "/home",
  },
];
